package com.pactera.asmp.server.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

import javax.servlet.MultipartConfigElement;

/**
 * @ProjectName: asmpserver
 * @Package: com.pactera.asmp.server.config
 * @ClassName: FileMultipartConfig
 * @Author: lvzhiqiang
 * @Description: 文件上传下载配置
 * @Date: 2019/8/27 15:17
 * @Version: 1.0
 */
@Configuration
public class FileMultipartConfig {

    /**
     * 单个文件最大
     */
    @Value("${multipart.maxFileSize}")
    private int maxFileSize = 50;

    /**
     * 总上传数据总大小
     */
    @Value("${multipart.maxRequestSize}")
    private int maxRequestSize = 100;

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize( DataSize.of(maxFileSize, DataUnit.MEGABYTES)); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(DataSize.of(maxRequestSize,DataUnit.MEGABYTES));
        return factory.createMultipartConfig();
    }
}
